/* proxyindex.rexx (0.63) 01-Aug-96 by mago@is-bremen.de Written for httpproxy 0.14 alpha (30-Jul-96) - Requirements: rexxtricks.library (Aminet), list, sort, type, echo, search - Using this script without an argument, it creates three index files, html sorted alpha. by time of file creation and an image page. Plus an AmigaGuide file, wich enables you to delete single Proxy-files by clicking on them (without warning). No Directorys are deleted. - The file rexx:proxydel.rexx will be written. It's used by the guide-file. - In an optional argument you can specify a searchpattern. All lines in in the html and the images page containing this string are written into {stem}g.html - This script works only on the /http/ dir, so far. */ /********* config *********/ centdok = 0 /* center links or align left (bool) */ striport = 1 /* strip port numbers from URL's (bool) */ port = 80 /* port on wich your proxy is running */ fontsize = 3 /* Between 1 and 6 */ cachedir = 'data:cache/' /* With trailing slash! */ stem = 'data:cache' /* stem of the resulting files. As there are: {stem}.html the main page, only html {stem}i.html the image page {stem}ts.html all html pages sorted by time {stem}g.html extract from both html pages {stem}.guide to delete single cache entries */ /* If your LOCALE language is not German you may have to change this var */ monthident = 'Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez' /**************************/ address command;parse arg pat;numfiles=0;status=1 /*'copy amitcp:bin/httpfetch ram:'*/ 'Resident >nil: c:list' if fontsize > 1 then do;bs=fontsize;hs=bs-1;end else do;bs=fontsize;hs=bs;end if length(pat) > 0 then call grep 'echo >'stem'cache.cont' if ~show('L','rexxtricks.library') then call addlib('rexxtricks.library',0,-30,0) tcnt=0;cnt=0;icnt=0 fn.0 = 14 fn.1 = '/* 'stem'.guide */;address command;parse arg string' fn.2 = 'if index(string,"@@") == 0 then "delete >nil: "string' fn.3 = 'else' fn.4 = 'do' fn.5 = ' off=index(string,@@)' fn.6 = ' roff=off' fn.7 = ' do while off > 0' fn.8 = ' roff=off' fn.9 = ' off=index(string,@@,off+1)' fn.10= ' end' fn.11= ' str=string' fn.12= ' str=delstr(insert("!",str,roff+1),roff,1)' fn.13= ' "delete >nil: "string" "str' fn.14= 'end' if ~writefile('rexx:proxydel.rexx',fn) then call ferr('rexx:proxydel.rexx') if ~open(tmp,'t:pi.tmp',w) then call ferr('t:pi.tmp') if ~open(tmpt,'t:timeindex.tmp',w) then call ferr('t:timeindex.tmp') if ~open(tmpx,'t:logx.tmp',w) then call ferr('t:logx.tmp') if ~open(tmpg,'t:logg.tmp',w) then call ferr('t:logg.tmp') if ~open(guide,stem'.guide',w) then call ferr(stem'.guide') call writeln(guide,'@database "Httpproxy.guide"') call writeln(guide,'@node main "Delete HttpProxy (0.14) Cache"') call close(guide) call htmlhead call getcont /* Explore the cachedir */ call writech(stdout,' 'numfiles' ') do i=1 to numfiles-1 /* Seperate files into page and image */ if index(upper(ofn.i),'.MOV') == 0 & index(upper(ofn.i),'.MPG') == 0 & index(upper(ofn.i),'NPH-COUNT') == 0 & index(upper(ofn.i),'.JPEG') == 0 & index(upper(ofn.i),'.GIF') == 0 & index(upper(ofn.i),'.JPG') == 0 then do call writeln tmp,''str(ofn.i)''stat()'
' call writeln tmpt,time.i' 'str(ofn.i)''stat()'
' trace off cnt=cnt+1 end else do call writeln tmpx,''str(ofn.i)''stat()'
' trace off icnt=icnt+1 end tcnt=tcnt+1 if tcnt == 101 then do tcnt=0 call writech(stdout,'*') end call writeln(tmpg,' @{ub}@{"'str(ofn.i)'" RX "rexx:proxydel.rexx 'ofp.i'"}@{ub}'stat()) trace off end call close(tmp);call close(tmpx);call close tmpg;call close tmpt;say /* creation of the final files */ 'Sort t:timeindex.tmp t:time.tmp' call tsortpage 'Sort t:logg.tmp t:loge.tmp' 'Type >>'stem'.guide t:loge.tmp' 'Echo >>'stem'.guide @endnode' 'Sort t:pi.tmp t:log2.tmp';'Sort t:logx.tmp t:logy.tmp' 'Type >>'stem'.html t:log2.tmp' if ~open(html,stem'.html',a) then call ferr(stem'.html') call writeln(html,cenl(0)'
')
call writeln(html,' Number of Pages: 'cnt'
') call writeln(html,'') call close(html) call gfxhead 'Type >>'stem'i.html t:logy.tmp' call open(html,stem'i.html',a) call writeln(html,cenl(0)'
')
call writeln(html,' Number of images: 'icnt'
') call writeln(html,'') call close(html) 'Delete >nil: t:#?.tmp' exit stat: if status then do if ofs.i == 'empty' then return ' 0 ' /* else This is dangerous to use! it discarded my cache! do 'ram:httpfetch >t:cont.tmp 'ofn.i' from localhost:80 ' if rc ~= 10 then do if ~open(ctst,'t:cont.tmp',r) then call ferr('t:ocnt.tmp') ad=readch(ctst,100) call close(ctst) if index(upper(ad),error) > 0 then return ' E ' else return '' end else return ' U ' end */ end else return '' cenl: parse arg switch if centdok then do if switch then return '
' else return '
' end else return '' tmod: /* DD-MMM-JJ HH:MM:SS -> JJMMDD HH to make it sortable and short */ return delstr(fd.i,1,7)||month(substr(fd.i,4,3))||substr(fd.i,1,2)' 'delstr(ft.i,3) month: /* convert the month abbrev. into number */ parse arg mt select when mt == word(monthident,1) then x='01' when mt == word(monthident,2) then x='02' when mt == word(monthident,3) then x='03' when mt == word(monthident,4) then x='04' when mt == word(monthident,5) then x='05' when mt == word(monthident,6) then x='06' when mt == word(monthident,7) then x='07' when mt == word(monthident,8) then x='08' when mt == word(monthident,9) then x='09' when mt == word(monthident,10) then x='10' when mt == word(monthident,11) then x='11' when mt == word(monthident,12) then x='12' otherwise nop end return x str: procedure parse arg t if index(t,'http://') > 0 then t=delstr(t,1,7) return t grep: if ~exists(stem'.html') then call ferr(stem'.html') if ~exists(stem'i.html') then call ferr(stem'i.html') if ~open(html,stem'g.html',w) then call ferr(stem'g.html') call writeln(html,'httpproxy index 'time(n)' 'date(e)'') call writeln(html,''cenl(1)) call close(html) 'Search >>'stem'g.html 'stem'.html 'pat' 'nonum 'Search >>'stem'g.html 'stem'i.html 'pat' 'nonum 'Echo >>'stem'g.html "'cenl(0)'"' exit ferr: parse arg fname say "Can't open: "fname exit htmlhead: /* html page */ if ~open(html,stem'.html',w) then call ferr(stem'.html') call writeln(html,'httpproxy in<>dex - html 'time(n)' 'date(e)'') call writeln(html,''cenl(1)) call close(html) return gfxhead: /* images page */ if ~open(html,stem'i.html',w) then call ferr(stem'.html') call writeln(html,'httpproxy index - ima<>ges 'time(n)' 'date(e)'') call writeln(html,''cenl(1)) call close(html) return tsortpage: /* time-sorted page */ if ~open(html,stem'ts.html',w) then call ferr(stem'ts.html') call writeln(html,'httpproxy index - html timesort 'time(n)' 'date(e)'') call writeln(html,''cenl(1)) tscnt=0 if ~readfile('t:time.tmp',fnt) then call ferr('t:time.tmp') tsc=fnt.0 /* reverse the timesort tmp to get the */ do i=1 to fnt.0 /* last request on top */ call writeln(html,fnt.tsc) tsc=tsc-1 end call writeln(html,cenl(0)'') call close(html) return getcont: /* Parse chachedir tree */ debug=0;cnt=1;stage=0 path=cachedir'http' call open(log,'ram:log',w) 'List >t:cdir.tmp lformat "%p%n %d %t %b" dates 'path if ~readlines('t:cdir.tmp',,,'%s %s %s %s','fn fd ft fs') then call ferr('t:cdir.tmp') do forever stage=stage+1 if debug then do say;say 'Processing Stage: 'stage;say say copies(#,50) say copies(#,16)' ident files 'copies(#,21) say copies(#,50) say;say 'Number of items: 'fn.0 end else call writech(stdout,'/') nextdir=0 do i=1 to fn.0 /* Processing of hash Files */ if index(fn.i,'@dirurl') > 0 | index(filepart(fn.i),'@@') > 0 | index(filepart(fn.i),'@!') > 0 then do if index(fn.i,'@dirurl') > 0 then do call open(fhandle,fn.i,r) htpath=readln(fhandle) call close(fhandle) end else do if index(filepart(fn.i),'@!') > 0 then do if fs.i == 'Dir' then /* if directory, queue to list */ do nextdir=nextdir+1 q.nextdir=fn.i end else do if ~open(fh,pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1),r) then call ferr(pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1)) numfiles=numfiles+1 ofp.numfiles=pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1) time.numfiles=tmod() ofn.numfiles=xport(readln(fh)||' 'striport);call close fh ofs.numfiles=fs.i if debug then do;say pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1)' 'fs.i;end end end end end else do if fs.i == 'Dir' then /* if directory, queue to list */ do nextdir=nextdir+1 q.nextdir=fn.i end else do call addout ofn.numfiles=ctourl(fn.i' 'striport' 'htpath) if debug then do;say left(fn.i,65)' 'fs.i;say 'htPath: 'htpath;end end end end if nextdir == 0 then break if debug then do say;say 'dirs to list';say do k=1 to nextdir say q.k end say;say copies(#,16)' list 'copies(#,26);say end flcnt=0 do i=1 to nextdir 'List >t:cdir.tmp lformat "%p%n %d %t %b" dates "'q.i'/#?"' if ~readlines('t:cdir.tmp',,,'%s %s %s %s','tfn tfd tft tfs') then call ferr('t:cdir.tmp') dul=lsearch('*@dirurl',tfn,,,p) /* @dirurl to start of list */ if dul > 1 then do tmp.1 = tfn.dul ; tfn.dul = tfn.1 ; tfn.1 = tmp.1 tmp.2 = tfd.dul ; tfd.dul = tfd.1 ; tfd.1 = tmp.2 tmp.3 = tft.dul ; tft.dul = tft.1 ; tft.1 = tmp.3 tmp.4 = tfs.dul ; tfs.dul = tfs.1 ; tfs.1 = tmp.4 end if tfn.0 > 0 then do acnt=1 if debug then do;say;say 'Dir contents of: 'q.i;say;end do j=flcnt to flcnt+tfn.0-1 flcnt=flcnt+1 fn.flcnt = tfn.acnt /* filename */ fd.flcnt = tfd.acnt /* filedate */ ft.flcnt = tft.acnt /* filetime */ fs.flcnt = tfs.acnt /* filezize */ if debug then say 'Fnr: 'flcnt' 'fn.flcnt' 'fs.flcnt acnt=acnt+1 end end end fn.0=flcnt if debug then say end return addout: /* Add an item to the output-list */ numfiles=numfiles+1 ofp.numfiles=fn.i time.numfiles=tmod() ofs.numfiles=fs.i return ctourl: procedure expose port /* Convert the filepath into URL */ parse arg t' 's' 'p t=p||filepart(t) if substr(t,length(t)) == @ then t=substr(t,1,length(t)-1) if port == substr(t, index(t,':',8)+1, index(t,'/',8)-index(t,':',8)-1) then if s then t=delstr(t, index(t,':',8),index(t,'/',8)-index(t,':',8)) /* strip port nr */ return t xport: procedure expose port parse arg t' 's if port == substr(t, index(t,':',8)+1, index(t,'/',8)-index(t,':',8)-1) then if s then t=delstr(t, index(t,':',8), index(t,'/',8)-index(t,':',8)) /* strip port nr */ return t /* eof */